package com.linhnv.app.coverfollow;

import com.facebook.android.DialogError;
import com.facebook.android.Facebook;
import com.facebook.android.Facebook.DialogListener;
import com.facebook.android.FacebookError;
import com.linhnv.app.coverfollow.adapter.ImageAdapter;
import com.linhnv.app.coverfollow.utils.Constant;
import com.linhnv.app.coverfollow.view.CoverFlow;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MyCoverFollowActivity extends Activity {
    /** Called when the activity is first created. */
	private Facebook mFacebook;
	private CoverFlow mCoverFlow;
	private Button mButton;
	private Context mContext;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext =this;
        setContentView(R.layout.main);
        mCoverFlow =(CoverFlow)findViewById(R.id.myView); 
        ImageAdapter coverImageAdapter =  new ImageAdapter(this);
       // coverImageAdapter.createReflectedImages();
        mCoverFlow.setAdapter(coverImageAdapter);
        mCoverFlow.setSpacing(-25);
        mCoverFlow.setSelection(4, true);
        mCoverFlow.setAnimationDuration(1000);        
        mButton =(Button)findViewById(R.id.btnShare);
        
        mFacebook=new Facebook(Constant.APP_ID);
        
        
        mButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
//				Log.e("Linhnv", "on btn share click !");
//				Intent sharingIntent = new Intent(Intent.ACTION_SEND);
//				Uri screenshotUri = Uri.parse("http://cyears.files.wordpress.com/2011/04/image4.jpg");
//				sharingIntent.setType("image/*");
//				sharingIntent.putExtra(Intent.EXTRA_TEXT, "Body text of the new status http://www.google.com");
//				sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
//				startActivity(Intent.createChooser(sharingIntent, "Share..."));
				
				
				mFacebook.authorize((Activity) mContext, new DialogListener(){

					@Override
					public void onComplete(Bundle values) {
						// TODO Auto-generated method stub
						Log.e("Linhnv","mFacebook.authorize : onComplete");
					}

					@Override
					public void onFacebookError(FacebookError e) {
						// TODO Auto-generated method stub
						Log.e("Linhnv","mFacebook.authorize : onComplete");
					}

					@Override
					public void onError(DialogError e) {
						// TODO Auto-generated method stub
						Log.e("Linhnv","mFacebook.authorize : onComplete");
					}

					@Override
					public void onCancel() {
						// TODO Auto-generated method stub
						Log.e("Linhnv","mFacebook.authorize : onComplete");
					}
					
				});

			}
		});
        
        
        
        
       
    }
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		
		mFacebook.authorizeCallback(requestCode, resultCode, data);
	}
}